﻿using System;
using System.Data;
using System.Data.Common;
using System.Globalization;
using Gammar.Price.ObjectModel;
using Longbow.Data;

namespace Gammar.Price.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public partial class OPENCLASS : ReaderCommand<OPENCLASSEntity>
    {   
        /// <summary>
        /// 
        /// </summary>            
        protected override CommandType CommandType
        {
            get { return CommandType.Text; }
        }

        private string _criteria;
        
        /// <summary>
        /// 
        /// </summary>
        public string Criteria
        {
            get { return _criteria; }
            set { _criteria = value; }
        }
        
        /// <summary>
        /// 
        /// </summary>
        protected override string CommandText
        {
            get
            {
                string sql = "select * from OPENCLASS";
                if (!string.IsNullOrEmpty(Criteria))
                    sql = string.Format(CultureInfo.InvariantCulture, "{0} {1}", sql, Criteria);
                return sql;
            }        
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override void AddParameters(DbParameterCollection parameters, DBAccess db)
        {

        }

        /// <summary>
        /// 
        /// </summary>            
        protected override OPENCLASSEntity ParseRow(DbDataReader reader)
        {
            OPENCLASSEntity obj = new OPENCLASSEntity();
            obj.Oc_id = (Guid?)DBAccess.ToObjectValue(reader["Oc_id"]);
            obj.Type = (Guid?)DBAccess.ToObjectValue(reader["Type"]);
            obj.Title = (string)DBAccess.ToObjectValue(reader["Title"]);
            obj.Originalprice = (string)DBAccess.ToObjectValue(reader["Originalprice"]);
            obj.Protomteprice = (string)DBAccess.ToObjectValue(reader["Protomteprice"]);
            obj.Teacher = (string)DBAccess.ToObjectValue(reader["Teacher"]);
            obj.Address = (string)DBAccess.ToObjectValue(reader["Address"]);
            obj.Presideunit = (string)DBAccess.ToObjectValue(reader["Presideunit"]);
            obj.Opendate = (string)DBAccess.ToObjectValue(reader["Opendate"]);
            obj.Contact = (string)DBAccess.ToObjectValue(reader["Contact"]);
            obj.Benefit = (string)DBAccess.ToObjectValue(reader["Benefit"]);
            obj.Imagepath = (string)DBAccess.ToObjectValue(reader["Imagepath"]);
            obj.Url = (string)DBAccess.ToObjectValue(reader["Url"]);
            obj.Brand = (string)DBAccess.ToObjectValue(reader["Brand"]);
            return obj;
        }
    }
}